package com.example.kafkaconsumer.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @Author: 朝花不迟暮
 * @Date: 2021/12/11 20:22
 * @Description:
 */
@Component
@Slf4j
public class KafkaConsumerService {

    @KafkaListener(groupId = "group02", topics = "topic02")
    public void onMessage(ConsumerRecord<String, Object> record,
                          Acknowledgment acknowledgment,
                          Consumer<?, ?> consumer) {
        log.info("消费端接受消息：{}", record);
        // 手工签收
        acknowledgment.acknowledge();
        log.info("消费端接受消息：{}", consumer);
    }
}